package com.yidian.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.yidian.dao.CategoryReportMapper;
import com.yidian.pojo.order.CategoryReport;
import com.yidian.server.order.CategoryReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

/**
 * @author whb
 * @create 2021-06-02 16:07
 * @desciption
 */
@Service(interfaceClass = CategoryReportService.class)
public class CategoryReportServiceImpl implements CategoryReportService {
    @Autowired
    private CategoryReportMapper categoryReportMapper;

    /**
     * 查询昨天的商品类目统计数据
     * @param date
     * @return
     */
    @Override
    public List<CategoryReport> categoryReport(LocalDate date) {
        return categoryReportMapper.categoryReport(date);
    }

    /**
     * 查询统计并保存（商品类目）
     */
    @Override
    @Transactional
    public void saveCategoryTj() {
        //LocalDate yesterdayDate=LocalDate.now().minusDays(1);
        LocalDate defaultDate=LocalDate.of(2019,4,15);
        List<CategoryReport> categoryReports = categoryReportMapper.categoryReport(defaultDate);
        if (categoryReports.size()>0){
            for (CategoryReport categoryReport:categoryReports) {
                categoryReportMapper.insertSelective(categoryReport);
            }
        }
    }

    /**
     * 按日期查询统计数据（商品一级类目）
     * @param beginDate
     * @param endDate
     * @return
     */
    @Override
    public List<Map> categoryId1Count(String beginDate, String endDate) {
        return categoryReportMapper.categoryId1Count(beginDate,endDate);
    }
}
